package com.fbt.andon.controller;


import com.fbt.andon.domain.Ng;
import com.fbt.andon.service.impl.NgServiceImpl;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * ng详情Controller
 *
 * @author fengtao
 * @date 2021-08-13
 */
@RestController
@RequestMapping("/ng")
@Api(description = "NG api")
public class NgController extends BaseController {
    @Autowired
    private NgServiceImpl ngService;


    /**
     * 查询该表所有信息
     */
    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/getNg")
    @ApiOperation("查询该表所有信息")
    public AjaxResult findNgList() {
        startPage();
        return AjaxResult.success("查询成功",ngService.list(null));
    }

    /**
     * 根据报废种类查询
     */
    @GetMapping("/getNgBySort")
    @ApiOperation("根据报废种类查询")
    //@PreAuthorize(hasPermi = "mes:andon:query")
    public AjaxResult findNgByMap(String ngSort) {
        startPage();
        HashMap<String, Object> map = new HashMap<>();
        // 自定义要查询
        map.put("ng_sort",ngSort);
        return AjaxResult.success("查询成功", ngService.listByMap(map));
    }

    /**
     * 获取ng详情详细信息
     */
  //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/getNgById/{id}")
    @ApiOperation("根据id获取ng详情详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success("获取成功",ngService.getById(id));
    }


    /**
     * 新增ng详情
     */
    //@PreAuthorize(hasPermi = "mes:andon:add")
    @ApiOperation("新增ng详情，参数ng")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Ng ng) {
         return AjaxResult.success("新增成功",ngService.save(ng));
    }

    /**
     * 修改ng详情
     */
    //@PreAuthorize(hasPermi = "mes:andon:edit")
    @ApiOperation("修改ng详情，参数ng")
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody Ng ng) {
        return AjaxResult.success("修改成功", ngService.updateById(ng));
    }

    /**
     * 删除ng详情
     */
   //@PreAuthorize(hasPermi = "mes:andon:remove")
    @ApiOperation("删除ng详情，参数ids")
    @PostMapping("/deletes/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
       return AjaxResult.success("删除成功", ngService.removeByIds(Arrays.asList(ids)));
    }
}
